package com.koron.css2.systemManage.servlet;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.systemManage.bean.OrgOperationBean;
import com.koron.css2.systemManage.bean.query.OrgOperationQueryBean;
import com.koron.css2.systemManage.service.ServiceFactory;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 添加组织操作
 * @author 59532
 *
 */
public class AddOrgOperation implements ServerInterface {

	private static Logger log = LogManager.getLogger(AddOrgOperation.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<OrgOperationBean> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "添加成功", OrgOperationBean.class);
		try {
			OrgOperationQueryBean bean = JsonUtils.objectToPojo(req.getData(), OrgOperationQueryBean.class);
			if(StringUtils.isEmpty(bean.getOrgCode())) {
				msg.setCode(Constant.MESSAGE_INT_FAIL);
				msg.setDescription("组织不能为空");
				return msg;
			}
			if(bean.getOperationCode() == null || bean.getOperationCode().size() == 0) {
				msg.setCode(Constant.MESSAGE_INT_FAIL);
				msg.setDescription("操作不能为空");
				return msg;
			}
			ServiceFactory.getOperationService().addOrgOperation(ApplicationConfig.getAppCustomerAppid(), bean.getOrgCode(), bean.getOperationCode());
		} catch (Exception e) {
			e.printStackTrace();
			log.error("新增菜单出错：" + e);
			msg.setCode(Constant.MESSAGE_INT_FAIL);
			msg.setDescription(e.getMessage());
		}
		return msg;
	}

}
